# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Maintainer: Peter Cai <peter at typeblog dot net>
# Thanks: Kevin MacMartin <prurigro at gmail dot com>

pkgname=shattered-pixel-dungeon
pkgver=2.0.1
pkgrel=2
pkgdesc='A roguelike dungeon crawler with randomized levels and enemies, and hundreds of items'
arch=('any')
url='https://shatteredpixel.com/shatteredpd/'
license=('GPL3')
depends=('bash' 'xorg-xrandr' 'java-runtime>=11' 'hicolor-icon-theme')
makedepends=('git' 'jdk11-openjdk' 'gradle')
_commit='22790c406e9308abb95ecf855118c0d01f8d41eb'
source=(
  "$pkgname::git+https://github.com/00-Evan/shattered-pixel-dungeon#commit=$_commit"
  "$pkgname.desktop"
  'wrapper.sh'
  'gradle-repro.patch'
)
b2sums=('SKIP'
        '94e110340bddcdf64d74922e9ddf4c0f37e72466ea61edcde61f903680f57b10d81ff804b95f2467e4364a577f7c845d66137fedfc700d11638defe6a3359a93'
        'c0b0d7d7319159716f1e49620c3c9a0bea9dea149cb1b88da0294a343341075557fe86bd45965a23aa34054ee6c454dd9a0b73273e6cafaf75de3d3fa3ef0ab1'
        '194480092028d1ab10b7bdb036233ba11984bd994346f9f6b925b7516da80f7214f8dff86e27054a5f9b792d1192732938d88f2121fd5207ad0a93aa5d571e0a')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  patch -p1 -i "$srcdir/gradle-repro.patch"
}

build() {
  cd "$pkgname"

  # Force the system to build the package using JDK 11
  export PATH="/usr/lib/jvm/java-11-openjdk/bin/:$PATH"
  export JAVA_HOME="/usr/lib/jvm/java-11-openjdk"

  gradle desktop:release
}

package() {
  cd "$pkgname"

  # wrapper script
  install -vDm755 "$srcdir/wrapper.sh" "$pkgdir/usr/bin/$pkgname"

  # jar file
  install -vDm644 "desktop/build/libs/desktop-$pkgver.jar" "$pkgdir/usr/share/$pkgname/$pkgname.jar"

  # desktop file
  install -vDm644 -t "$pkgdir/usr/share/applications" "$srcdir/$pkgname.desktop"

  # application icons
  for i in 16 32 48 64 128 256; do
    install -vDm644 "desktop/src/main/assets/icons/icon_${i}.png" "$pkgdir/usr/share/icons/hicolor/${i}x${i}/apps/$pkgname.png"
  done
  install -vDm644 android/src/main/res/mipmap-xxxhdpi/ic_launcher.png "$pkgdir/usr/share/icons/hicolor/192x192/apps/$pkgname.png"
}
